<!DOCTYPE html>
<html>
<head>
    <title>攻略系列</title>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"/>
    <link rel="stylesheet" href="/js/bootstrap/css/bootstrap.min.css"/>
    <script src="/js/jquery/jquery.min.js"></script>
    <script src="/js/bootstrap/js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="/css/font/css/font-awesome.min.css"/>
    <link rel="stylesheet" href="/css/reset.css"/>
    <link rel="stylesheet" href="/css/strategyCatalogs.css"/>
    <link rel="stylesheet" href="/js/plugins/dialog/dialog.css"/>
    <script src="/js/plugins/jrender/jrender.js"></script>
    <script src="/js/plugins/dialog/dialog.min.js"></script>
    <script src="/js/common.js"></script>
    <script src="/js/function.js"></script>
    <script src="/js/function.js"></script>
    <script>
        var user = JSON.parse(sessionStorage.getItem("user"));
        var currentPage = 1; //当前页
        var pages; //总页数
        var comments; //评论数组

        $(function () {


            var user = JSON.parse(sessionStorage.getItem("user"));

            var strategyId = getParams().strategyId;
            var likenum;
            //发送请求获取当前的攻略信息
            $.get("/strategies/"+strategyId, function (data) {
                $("#title").html(data.title);//标题
                $("#likes").html(data.likes);//点赞数
                $("#collects").html(data.collects);//收藏数
                likenum = data.likes;
            $.get("/strategies/" + strategyId, function (data) {
                $("#title").html(data.title);
            });
            //发送ajax请求获取当前攻略的分类
            $.get("/strategies/"+strategyId+"/catalogs", function (data) {
                var num = 1;
                $("#pills-catalog .catalogs").renderValues({list: data}, {
                    showTitle: function (ele, value) {
                        // 01/概况
                        var content = (num++)+"/"+value;
                        if (num < 10) {
                            content = 0 + content;
                        }
                        ele.innerHTML = content;
                    },
                    handle: function (ele, value) {
                        ele.href = "/strategyDetails.html?id=" + value;
                    }
                });
            });


            if (user != null) {
                 $.get("/collects/users/get", {type: 1, collectId: strategyId,userId:user.id}, function (data) {
                    if (data) {
                        $("#collectBtn").removeClass("fa fa-heart-o fa-1x");
                        $("#collectBtn").addClass("fa fa-heart fa-1x");
                    }else{
                        $("#collectBtn").removeClass("fa fa-heart fa-1x");
                        $("#collectBtn").addClass("fa fa-heart-o fa-1x");
                    }
                 })
            }

            //点击评论跳转到攻略评论页面
            $("#commentBtn").click(function () {
                if (!user) {
                    $(document).dialog({
                        type: "confirm",
                        style: "IOS",
                        titleShow: false,
                        content: "亲，还没登录不能评论哦！，",
                        buttons: [{
                            name: "马上登录",
                            callback: function () {
                                location.href = "/login.html";
                            }
                        }]
                    });
                    return;
                }
                window.location.href = "/addComment.html?id=" + strategyId;
            })

            //查询该攻略的评论标签
            $.get("/strategies/" + strategyId + "/tags", function (data) {
                var taghtml = "";
                $.each(data, function (index, ele) {
                    if (index < 10) {
                        taghtml += "<span>" + ele.name + "</span>";
                    }
                })
                $("#tags").html(taghtml);
            })

            $.get("/strategies/comments/" + strategyId, {currentPage: 1, pageSize: 3}, function (data) {
                pages = data.pages;
                comments = data.list;
                $("#comment").renderValues(data, {
                    stars: function (ele, value) {
                        ele.setAttribute("id", value);
                    },
                    img: function (ele, value) {
                        ele.setAttribute("id", "0" + value);
                    },
                    link: function (ele, value) {
                        ele.href = "strategyComment.html?id=" + value;
                    },
                    userinfo: function (ele, value) {
                        ele.href = "mine/userProfiles.html?id=" + value;
                    }
                });

                $.each(data.list, function (index, value) {
                    //显示星星评价
                    var starhtml = "";
                    for (var i = 0; i < value.starNum; i++) {
                        starhtml += '<i class="fa fa-star"></i>';
                    }
                    for (var i = value.starNum; i < 5; i++) {
                        starhtml += '<i class="fa fa-star-o"></i>';
                    }
                    $(".comment-star[data-starid ='" + value.id + "']").html(starhtml);
                    $(".icon[data-commentid ='" + value.id + "']").attr("href", "strategyDetails.html?id=" + value.id);
                    //显示评论的图片,拼接方式
                    var imgshtml = "";
                    var imgs = value.imgUrls.split(";");
                    for (var i = 0; i < imgs.length - 1; i++) {
                        imgshtml += '<li><img  src="' + imgs[i] + '"></li>';
                    }
                    $("#0" + value.id).html(imgshtml);
                })
            })

            $(window).scroll(function () {
                if (isEnd()) {
                    if (currentPage < pages) {
                        currentPage++;
                        $.get("/strategies/comments/" + strategyId, {
                            currentPage: currentPage,
                            pageSize: 3
                        }, function (data) {
                            //数据渲染
                            $.merge(comments, data.list);
                            console.log(comments);
                            $("#comment").renderValues({list: comments}, {
                                stars: function (ele, value) {
                                    ele.setAttribute("id", value);
                                },
                                img: function (ele, value) {
                                    ele.setAttribute("id", "0" + value);
                                },
                                link: function (ele, value) {
                                    ele.href = "strategyComment.html?id=" + value;
                                }
                            });
                            $.each(comments, function (index, value) {
                                //显示星星评价
                                var starhtml = "";
                                for (var i = 0; i < value.starNum; i++) {
                                    starhtml += '<i class="fa fa-star"></i>';
                                }
                                for (var i = value.starNum; i < 5; i++) {
                                    starhtml += '<i class="fa fa-star-o"></i>';
                                }
                                $(".comment-star[data-starid ='" + value.id + "']").html(starhtml);
                                $(".icon[data-commentid ='" + value.id + "']").attr("href", "strategyDetails.html?id=" + value.id);
                                //显示评论的图片,拼接方式
                                var imgshtml = "";
                                var imgs = value.imgUrls.split(";");
                                for (var i = 0; i < imgs.length - 1; i++) {
                                    imgshtml += '<li><img  src="' + imgs[i] + '"></li>';
                                }
                                $("#0" + value.id).html(imgshtml);
                            })
                        })
                    }
                    else {
                        $(document).dialog({
                            type: "notice",
                            infoText: "已经到底部了",
                            autoClose: 1500,
                            position: "center"
                        });
                    }
                }
            })


            //发送ajax请求获取当地热门游记
            $.get("/strategies/" + strategyId + "/travels", function (data) {
                var num = 1;
                $(".hot").renderValues({list: data}, {
                    handle: function (ele, value) {
                        ele.href = "/travelContent.html?id=" + value;
                    }
                });
            });

        //收藏事件
        $("#collectBtn").click(function () {
            collect(user,strategyId,1);
        })
        //点赞事件
        $("#likeBtn").click(function () {
           like(user,strategyId,1);//点赞:1:攻略点赞，2：评论点赞
        })


    });

    //评论点赞
    function updatelike() {
    }


        });
    </script>
</head>

<body>
<div class="search-head">
    <div class="row nav-search">
        <div class="col-2">
            <a href="javascript:history.go(-1);">
                <span><i class="fa fa-chevron-left fa-1x"></i></span>
            </a>
        </div>
        <div class="col-10">
            <div class="input-group-sm search">
                <input class="form-control searchBtn" placeholder="搜索旅行攻略">
            </div>
        </div>
    </div>
</div>

<div class="container strategies">
    <h5 class="title" id="title"></h5>
    <small><span>0</span>人阅读过此攻略</small>
    <div class="focus">
        <!--<i class="" id="collectBtn">收藏</i>-->
        <!--$("#collectBtn").removeClass("fa fa-heart-o fa-1x");-->
        <i class="fa fa-heart-o" id="collectBtn"><span id="collects">0</span> 收藏</i>
        <i class="fa fa-thumbs-o-up" id="likeBtn"><span id="likes">0</span> 点赞</i>
        <button class="btn">想去</button>
        <button class="btn">去过</button>
    </div>
</div>
<ul class="nav nav-pills nav-justified border border-left-0 border-top-0 border-right-0" id="pills-tab">
    <li class="nav-item ">
        <a class="nav-link active" id="pills-catalog-tab" data-toggle="pill" href="#pills-catalog">
            <span>攻略目录</span>
        </a>
    </li>
    <li class="nav-item">
        <a class="nav-link " id="pills-comment-tab" data-toggle="pill" href="#pills-comment">
            <span>骡友点评</span>
        </a>
    </li>
</ul>
<div class="tab-content " id="pills-tabContent">
    <div class="tab-pane fade show active" id="pills-catalog">
        <div class="container hot">
            <h6>大家都在看</h6>
            <div render-loop="list">
                <a href="travelContent.html" render-key="list.id" render-fun="handle">
                    <button class="btn" render-html="list.title"></button>
                </a>
            </div>
        </div>
        <div class="catalogs">
            <div render-loop="list">
                <div class="container detail">
                    <h6 render-key="list.name" render-fun="showTitle"></h6>
                    <div render-loop="list.details">
                        <a href="strategyDetails.html" render-key="list.details.id" render-fun="handle">
                            <button class="btn" render-html="list.details.title"></button>
                        </a>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="tab-pane fade " id="pills-comment">

        <div class="container tag">
            <h6>骡友标签</h6>
            <div id="tags">
            </div>
        </div>
        <hr>

        <div id="comment">
            <div render-loop="list">
                <div class="container row comment">
                    <div class="col-2 comment-head">
                        <a render-key="list.user.id" render-fun="userinfo">
                            <img class="rounded-circle" render-src="list.user.headImgUrl">
                        </a>
                    </div>

                    <div class="col comment-right">
                        <p class="authorName"><span render-html="list.user.nickName"></span></p>


                        <div class="stars">
                            <span class="comment-star" render-attr="data-starid=list.id"> </span>
                            <i class="fa fa-calendar"></i><span render-html="list.commentTime"></span>
                        </div>


                        <div class="comment-content">
                            <a href="strategyComment.html">
                                <p render-html="list.comment"></p>
                            </a>
                        </div>
                        <ul class="comment-img" render-key="list.id" render-fun="img">
                        </ul>
                        <div class="d-flex icon">
                            <a href="strategyComment.html" render-key="list.id" render-fun="link">
                                <i class="fa  fa-commenting-o " style="margin-right: 10px"> 评论 </i>
                            </a>

                            <a href="javascript:updatelike()">
                                <i class="fa fa-thumbs-o-up"> <span render-html="list.likes"></span> </i>
                            </a>
                        </div>
                    </div>
                </div>

            </div>
        </div>
    </div>
</div>
</div>

<div class="operation">
    <button class="btn">加入旅行单</button>
    <button class="btn" id="commentBtn">点评</button>
</div>


</body>
</html>